<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2021.3.24
 * Time: 13:36
 */

class Solution
{
    public function reverseString(&$array)
    {
        $arrLen = count($array);
        if($arrLen == 0) {
            return [];
        }

        if($arrLen == 1) {
            return $array;
        }

        $mid = $arrLen / 2;

        for ($i=0;$i < $mid;$i++) {
            $temp = $array[$i];
            $array[$i] = $array[$arrLen-1-$i]; // 算出偏移量
            $array[$arrLen-1-$i] = $temp;
        }

        return $array;
    }
}

$array = ["h","e","l","l","o"];
// ["o","l","l","e","h"]
$s = new Solution();
$res = $s->reverseString($array);
print_r($res);